//
//  MBDTabBarController.swift
//  MasterBoy
//
//  Created by kyson on 2023/3/15.
//

import Foundation
import UIKit
import Reachability
import Alamofire

class MBDTabBarController: UITabBarController {
    
    init() {
        super.init(nibName:  nil , bundle:  nil )
        
        let bar = self.tabBar
        if #available(iOS 13.0, *) {
            let appear = UITabBarAppearance()
//            appear.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor(colorHex: 0x333333)]
            appear.setDynamicTabBarBackgroundColor()
            bar.standardAppearance = appear
            bar.isTranslucent = false
//            bar.scrollEdgeAppearance = appear
            //从 iOS 15 开始，UINavigationBar、UIToolbar 和 UITabBar 将在你的VC关联滚动视图位于适当的边缘时使用 scrollEdgeAppearance（或者如果您的试图层级结构中没有 UIScrollView)。
            if #available(iOS 15.0, *) {
                bar.scrollEdgeAppearance = appear
            }

        } else {
            // Fallback on earlier versions
        }

        
        let vc1 = MBDMainViewController();
        var homeImageHighlighted = UIImage(named: "tab_home_hl")
        homeImageHighlighted = homeImageHighlighted?.withRenderingMode(.alwaysOriginal)
        
        var homeImageNormal = UIImage(named: "tab_home_nm")
        homeImageNormal = homeImageNormal?.withRenderingMode(.alwaysOriginal)
        
        vc1.tabBarItem = UITabBarItem(title: "首页", image: homeImageNormal, selectedImage: homeImageHighlighted)
        
        
        let navi = MBDNavigationController(rootViewController: vc1)
        
        ////
        let vc2 = MBDMessageViewController();
        vc2.title = "消息";
        
        var messageHighlighted = UIImage(named: "tab_msg_hl")
        messageHighlighted = messageHighlighted?.withRenderingMode(.alwaysOriginal)
        
        var messageNormal = UIImage(named: "tab_msg_nm")
        messageNormal = messageNormal?.withRenderingMode(.alwaysOriginal)
        
        vc2.tabBarItem = UITabBarItem(title: "消息", image: messageNormal, selectedImage: messageHighlighted)
        
        let navi2 = MBDNavigationController(rootViewController: vc2)

        
        ////
        let vc3 = MBDMineViewController();
        var mineImageHighlighted = UIImage(named: "tab_mine_hl")
        mineImageHighlighted = mineImageHighlighted?.withRenderingMode(.alwaysOriginal)
        
        var mineImageNormal = UIImage(named: "tab_mine_nm")
        mineImageNormal = mineImageNormal?.withRenderingMode(.alwaysOriginal)
        
        vc3.tabBarItem = UITabBarItem(title: "我的", image: mineImageNormal, selectedImage: mineImageHighlighted)
        
        let navi3 = MBDNavigationController(rootViewController: vc3)
        
//        UINavigationBar.appearance().setDynamicNavigationBarBackgroundColor()

        self.viewControllers = [navi,navi2,navi3]
        
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
}
